package com.javabasic;

/**
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see
 * @since Created by work on 2022/1/18 8:22 下午
 */
public class AliTestOne {

    public static void main(String[] args) {
//        int[] nums1 = new int[]{1,2,3,0,0,0};
//        int[] nums2 = new int[]{2,5,6};

        int[] nums1 = new int[]{1,3,6,7,0,0,0};
        int[] nums2 = new int[]{2,5,9};
        mergeArray(nums1,nums2);
        for (int num : nums1) {
            System.out.print(num + " ");
        }
    }

    public static void mergeArray(int[] arr1, int[] arr2) {
        int len1 = arr1.length;
        int len2 = arr2.length;
        int tag = len2-1;
        for (int i = len1-1; tag >= 0; i--) {
            arr1[i] = arr2[tag--];
        }


        quickSort(arr1,0,len1-1);

    }

    public static void quickSort(int[] nums, int left, int right) {
        if (left < right) {
            int tag = executeSort(nums,left,right);
            quickSort(nums,left,tag-1);
            quickSort(nums,tag+1, right);
        }
    }

    private static int executeSort(int[] nums, int left, int right) {
        int tagNum = nums[left];
        while (left < right) {
            while (nums[right] > tagNum && right > left) {
                right--;
            }
            nums[left] = nums[right];
            while (nums[left] <= tagNum && right > left) {
                left++;
            }
            nums[right] = nums[left];
            nums[left] = tagNum;
        }
        return left;
    }
}
